import 'dart:convert';
import 'dart:math';

import 'package:get/get_rx/src/rx_types/rx_types.dart';

/// userId : "921b059b-bf62-4df0-9e7f-c5f54f3bda22"
/// userName : "王亚东"
/// loginName : "15093185254"
/// loginType : null
/// headUrl : null
/// token : "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ7XCJhcHBDb2RlXCI6XCJEU1gtUEVBUlwiLFwidXNlcklkXCI6XCI5MjFiMDU5Yi1iZjYyLTRkZjAtOWU3Zi1jNWY1NGYzYmRhMjJcIn0iLCJpc3MiOiJ0b3B4bi11aWFzIiwiaWF0IjoxNjUwMjQ5ODQxLCJleHAiOjE2NTA4NTQ2NDEsIm5iZiI6MTY1MDI0OTg0MX0.QXk7jbsY3SM7rU8Qth9WWvlv-JlzL_1trZYkRzwA5Qg"
/// loginTime : "2022-04-18T02:44:01.726+0000"
/// expiresMillisecond : 604800000
/// tenantId : "DSX-PEAR"
/// appId : "A20211202140446825"
/// appCode : "A20211202140446825"
/// userType : 2
/// checkedIdentity : null
/// uiasRoleList : [{"roleId":"7f8da0b5-fb76-48ca-ab0b-6d8caf106934","roleName":"生产科长","roleCode":"PRODUCTION_SECTION_CHIEF","sourceId":"921b059b-bf62-4df0-9e7f-c5f54f3bda22","sourceType":"U","roleType":2}]
/// menuIds : null
/// appCodes : ["A20220411164210620","A20220411165014971"]
/// userOrgPostDTOList : [{"orgPostId":"a1dd5dac-3f21-4470-9ef8-dc2d808d1375","orgId":"f1ad938e-fca7-49f8-a5fb-72f490c2be06","orgName":"测试梨园基地公司","postId":"1ff98c05-aeb3-4cdd-b023-c71a3aa1c978","postName":"生产科长","districtLevel":"1130","isDefault":1,"orgAlias":"基地公司","orgType":"0300"},{"orgPostId":"46ab6c8c-0ae6-4919-8e13-e841cd940864","orgId":"9748ee79-3778-4edd-af46-5ca99b85ef28","orgName":"测试生产部门","postId":"0fbc2080-1084-43dd-9d1a-30004caffc8c","postName":"生产科长","districtLevel":"1140","isDefault":0,"orgAlias":"生产部门","orgType":"0300"}]
/// permissionMenus : null
/// permissionMenuDTOS : null
/// loginPostInfo : {"orgPostId":"a1dd5dac-3f21-4470-9ef8-dc2d808d1375","orgId":"f1ad938e-fca7-49f8-a5fb-72f490c2be06","orgName":"测试梨园基地公司","postId":"1ff98c05-aeb3-4cdd-b023-c71a3aa1c978","postName":"生产科长","districtLevel":"1130","isDefault":1,"orgAlias":"基地公司","orgType":"0300"}
/// roleVOList : [{"userId":null,"roleCode":"A20220411164210620","roleName":null,"orgPostRoleType":null},{"userId":null,"roleCode":"A20220411165014971","roleName":null,"orgPostRoleType":null}]
enum UserRole {
  FARM_ADMIN, //管理员 负责地块和设备的管理
  PRODUCTION_SECTION_CHIEF, //生产科长 负责维修物联网设备
  TECHNICIAN, //技术员 负责上报问题、下发给分厂厂长任务。
  BRANCH_DIRECTOR, //分厂厂长 负责接收任务和下发给执行员任务
  MARSHAL, //执行员 负责接收分厂厂长的任务，对具体地块执行任务。
  BUYER, //采购员
  REPAIRMAN, //维修员 负责维修物联网设备
}

UserInfo userInfoFromJson(String str) => UserInfo.fromJson(json.decode(str));
String userInfoToJson(UserInfo data) => json.encode(data.toJson());

class UserInfo {
  UserInfo({
    String? userId,
    String? userName,
    String? loginName,
    dynamic loginType,
    dynamic headUrl,
    String? token,
    String? loginTime,
    int? expiresMillisecond,
    String? tenantId,
    String? appId,
    String? appCode,
    int? userType,
    dynamic checkedIdentity,
    List<UiasRoleList>? uiasRoleList,
    dynamic menuIds,
    List<String>? appCodes,
    List<UserOrgPostDtoList>? userOrgPostDTOList,
    dynamic permissionMenus,
    dynamic permissionMenuDTOS,
    LoginPostInfo? loginPostInfo,
    List<RoleVoList>? roleVOList,
  }) {
    _userId = userId;
    _userName = userName;
    _loginName = loginName;
    _loginType = loginType;
    _headUrl = headUrl;
    _token = token;
    _loginTime = loginTime;
    _expiresMillisecond = expiresMillisecond;
    _tenantId = tenantId;
    _appId = appId;
    _appCode = appCode;
    _userType = userType;
    _checkedIdentity = checkedIdentity;
    _uiasRoleList = uiasRoleList;
    _menuIds = menuIds;
    _appCodes = appCodes;
    _userOrgPostDTOList = userOrgPostDTOList;
    _permissionMenus = permissionMenus;
    _permissionMenuDTOS = permissionMenuDTOS;
    _loginPostInfo = loginPostInfo;
    _roleVOList = roleVOList;
  }

  void updateAvater(String avater) {
    _headUrl = avater;
  }

  UserInfo.fromJson(dynamic json) {
    _userId = json['userId'];
    _userName = json['userName'];
    _loginName = json['loginName'];
    _loginType = json['loginType'];
    _headUrl = json['headUrl'];
    _token = json['token'];
    _loginTime = json['loginTime'];
    _expiresMillisecond = json['expiresMillisecond'];
    _tenantId = json['tenantId'];
    _appId = json['appId'];
    _appCode = json['appCode'];
    _userType = json['userType'];
    _checkedIdentity = json['checkedIdentity'];
    if (json['uiasRoleList'] != null) {
      _uiasRoleList = [];
      json['uiasRoleList'].forEach((v) {
        _uiasRoleList?.add(UiasRoleList.fromJson(v));
      });
      if (_uiasRoleList!.length > 0) {
        if (json['uiasRole'] == null) {
          uiasRole = _uiasRoleList!.first;
        } else {
          uiasRole = UiasRoleList.fromJson(json['uiasRole']);
        }
      }
    }
    _menuIds = json['menuIds'];
    _appCodes = json['appCodes'] != null ? json['appCodes'].cast<String>() : [];
    if (json['userOrgPostDTOList'] != null) {
      _userOrgPostDTOList = [];
      json['userOrgPostDTOList'].forEach((v) {
        _userOrgPostDTOList?.add(UserOrgPostDtoList.fromJson(v));
      });
    }
    _permissionMenus = json['permissionMenus'];
    _permissionMenuDTOS = json['permissionMenuDTOS'];
    _loginPostInfo = json['loginPostInfo'] != null
        ? LoginPostInfo.fromJson(json['loginPostInfo'])
        : null;
    if (json['roleVOList'] != null) {
      _roleVOList = [];
      json['roleVOList'].forEach((v) {
        var _role = RoleVoList.fromJson(v);
        _roleVOList?.add(_role);
      });
    }

    localIMfreshTime = _loginTime;

  }
  String? _userId;
  String? _userName;
  String? _loginName;
  dynamic _loginType;
  dynamic _headUrl;
  String? _token;
  String? _loginTime;
  int? _expiresMillisecond;
  String? _tenantId;
  String? _appId;
  String? _appCode;
  int? _userType;
  dynamic _checkedIdentity;
  List<UiasRoleList>? _uiasRoleList;
  dynamic _menuIds;
  List<String>? _appCodes;
  List<UserOrgPostDtoList>? _userOrgPostDTOList;
  dynamic _permissionMenus;
  dynamic _permissionMenuDTOS;
  LoginPostInfo? _loginPostInfo;
  List<RoleVoList>? _roleVOList;
  UserRole? _role;

  String? get userId => _userId;
  String? get userName => _userName;
  String? get loginName => _loginName;
  dynamic get loginType => _loginType;
  dynamic get headUrl => _headUrl;
  String? get token => _token;
  String? get loginTime => _loginTime;
  int? get expiresMillisecond => _expiresMillisecond;
  String? get tenantId => _tenantId;
  String? get appId => _appId;
  String? get appCode => _appCode;
  int? get userType => _userType;
  dynamic get checkedIdentity => _checkedIdentity;
  List<UiasRoleList>? get uiasRoleList => _uiasRoleList;
  dynamic get menuIds => _menuIds;
  List<String>? get appCodes => _appCodes;
  List<UserOrgPostDtoList>? get userOrgPostDTOList => _userOrgPostDTOList;
  dynamic get permissionMenus => _permissionMenus;
  dynamic get permissionMenuDTOS => _permissionMenuDTOS;
  LoginPostInfo? get loginPostInfo => _loginPostInfo;
  List<RoleVoList>? get roleVOList => _roleVOList;

  String? localIMfreshTime ;

  UserRole? get role {
    var _roleCode = uiasRole.roleCode;
    if (_roleCode == 'FARM_ADMIN') {
      _role = UserRole.FARM_ADMIN;
    } else if (_roleCode == 'PRODUCTION_SECTION_CHIEF') {
      _role = UserRole.PRODUCTION_SECTION_CHIEF;
    } else if (_roleCode == 'TECHNICIAN') {
      _role = UserRole.TECHNICIAN;
    } else if (_roleCode == 'BRANCH_DIRECTOR') {
      _role = UserRole.BRANCH_DIRECTOR;
    } else if (_roleCode == 'MARSHAL') {
      _role = UserRole.MARSHAL;
    } else if (_roleCode == 'BUYER') {
      _role = UserRole.BUYER;
    } else if (_roleCode == 'REPAIRMAN') {
      _role = UserRole.REPAIRMAN;
    }
    return _role;
  }

  UiasRoleList get uiasRole => uiasRoleObs.value;
  set uiasRole(val) => uiasRoleObs.value = val;
  var uiasRoleObs = UiasRoleList().obs;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['userId'] = _userId;
    map['userName'] = _userName;
    map['loginName'] = _loginName;
    map['loginType'] = _loginType;
    map['headUrl'] = _headUrl;
    map['token'] = _token;
    map['loginTime'] = _loginTime;
    map['expiresMillisecond'] = _expiresMillisecond;
    map['tenantId'] = _tenantId;
    map['appId'] = _appId;
    map['appCode'] = _appCode;
    map['userType'] = _userType;
    map['checkedIdentity'] = _checkedIdentity;
    if (_uiasRoleList != null) {
      map['uiasRoleList'] = _uiasRoleList?.map((v) => v.toJson()).toList();
    }
    map['menuIds'] = _menuIds;
    map['appCodes'] = _appCodes;
    if (_userOrgPostDTOList != null) {
      map['userOrgPostDTOList'] =
          _userOrgPostDTOList?.map((v) => v.toJson()).toList();
    }
    map['permissionMenus'] = _permissionMenus;
    map['permissionMenuDTOS'] = _permissionMenuDTOS;
    if (_loginPostInfo != null) {
      map['loginPostInfo'] = _loginPostInfo?.toJson();
    }
    if (_roleVOList != null) {
      map['roleVOList'] = _roleVOList?.map((v) => v.toJson()).toList();
    }
    map['localIMfreshTime'] = localIMfreshTime;

    map['uiasRole'] = uiasRole.toJson();
    return map;
  }
}

/// userId : null
/// roleCode : "A20220411164210620"
/// roleName : null
/// orgPostRoleType : null

RoleVoList roleVoListFromJson(String str) =>
    RoleVoList.fromJson(json.decode(str));
String roleVoListToJson(RoleVoList data) => json.encode(data.toJson());

class RoleVoList {
  RoleVoList({
    dynamic userId,
    String? roleCode,
    dynamic roleName,
    dynamic orgPostRoleType,
  }) {
    _userId = userId;
    _roleCode = roleCode;
    _roleName = roleName;
    _orgPostRoleType = orgPostRoleType;
  }

  RoleVoList.fromJson(dynamic json) {
    _userId = json['userId'];
    _roleCode = json['roleCode'];
    _roleName = json['roleName'];
    _orgPostRoleType = json['orgPostRoleType'];
  }
  dynamic _userId;
  String? _roleCode;
  dynamic _roleName;
  dynamic _orgPostRoleType;

  dynamic get userId => _userId;
  String? get roleCode => _roleCode;
  dynamic get roleName => _roleName;
  dynamic get orgPostRoleType => _orgPostRoleType;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['userId'] = _userId;
    map['roleCode'] = _roleCode;
    map['roleName'] = _roleName;
    map['orgPostRoleType'] = _orgPostRoleType;
    return map;
  }
}

/// orgPostId : "a1dd5dac-3f21-4470-9ef8-dc2d808d1375"
/// orgId : "f1ad938e-fca7-49f8-a5fb-72f490c2be06"
/// orgName : "测试梨园基地公司"
/// postId : "1ff98c05-aeb3-4cdd-b023-c71a3aa1c978"
/// postName : "生产科长"
/// districtLevel : "1130"
/// isDefault : 1
/// orgAlias : "基地公司"
/// orgType : "0300"

LoginPostInfo loginPostInfoFromJson(String str) =>
    LoginPostInfo.fromJson(json.decode(str));
String loginPostInfoToJson(LoginPostInfo data) => json.encode(data.toJson());

class LoginPostInfo {
  LoginPostInfo({
    String? orgPostId,
    String? orgId,
    String? orgName,
    String? postId,
    String? postName,
    String? districtLevel,
    int? isDefault,
    String? orgAlias,
    String? orgType,
  }) {
    _orgPostId = orgPostId;
    _orgId = orgId;
    _orgName = orgName;
    _postId = postId;
    _postName = postName;
    _districtLevel = districtLevel;
    _isDefault = isDefault;
    _orgAlias = orgAlias;
    _orgType = orgType;
  }

  LoginPostInfo.fromJson(dynamic json) {
    _orgPostId = json['orgPostId'];
    _orgId = json['orgId'];
    _orgName = json['orgName'];
    _postId = json['postId'];
    _postName = json['postName'];
    _districtLevel = json['districtLevel'];
    _isDefault = json['isDefault'];
    _orgAlias = json['orgAlias'];
    _orgType = json['orgType'];
  }
  String? _orgPostId;
  String? _orgId;
  String? _orgName;
  String? _postId;
  String? _postName;
  String? _districtLevel;
  int? _isDefault;
  String? _orgAlias;
  String? _orgType;

  String? get orgPostId => _orgPostId;
  String? get orgId => _orgId;
  String? get orgName => _orgName;
  String? get postId => _postId;
  String? get postName => _postName;
  String? get districtLevel => _districtLevel;
  int? get isDefault => _isDefault;
  String? get orgAlias => _orgAlias;
  String? get orgType => _orgType;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['orgPostId'] = _orgPostId;
    map['orgId'] = _orgId;
    map['orgName'] = _orgName;
    map['postId'] = _postId;
    map['postName'] = _postName;
    map['districtLevel'] = _districtLevel;
    map['isDefault'] = _isDefault;
    map['orgAlias'] = _orgAlias;
    map['orgType'] = _orgType;
    return map;
  }
}

/// orgPostId : "a1dd5dac-3f21-4470-9ef8-dc2d808d1375"
/// orgId : "f1ad938e-fca7-49f8-a5fb-72f490c2be06"
/// orgName : "测试梨园基地公司"
/// postId : "1ff98c05-aeb3-4cdd-b023-c71a3aa1c978"
/// postName : "生产科长"
/// districtLevel : "1130"
/// isDefault : 1
/// orgAlias : "基地公司"
/// orgType : "0300"

UserOrgPostDtoList userOrgPostDtoListFromJson(String str) =>
    UserOrgPostDtoList.fromJson(json.decode(str));
String userOrgPostDtoListToJson(UserOrgPostDtoList data) =>
    json.encode(data.toJson());

class UserOrgPostDtoList {
  UserOrgPostDtoList({
    String? orgPostId,
    String? orgId,
    String? orgName,
    String? postId,
    String? postName,
    String? districtLevel,
    int? isDefault,
    String? orgAlias,
    String? orgType,
  }) {
    _orgPostId = orgPostId;
    _orgId = orgId;
    _orgName = orgName;
    _postId = postId;
    _postName = postName;
    _districtLevel = districtLevel;
    _isDefault = isDefault;
    _orgAlias = orgAlias;
    _orgType = orgType;
  }

  UserOrgPostDtoList.fromJson(dynamic json) {
    _orgPostId = json['orgPostId'];
    _orgId = json['orgId'];
    _orgName = json['orgName'];
    _postId = json['postId'];
    _postName = json['postName'];
    _districtLevel = json['districtLevel'];
    _isDefault = json['isDefault'];
    _orgAlias = json['orgAlias'];
    _orgType = json['orgType'];
  }
  String? _orgPostId;
  String? _orgId;
  String? _orgName;
  String? _postId;
  String? _postName;
  String? _districtLevel;
  int? _isDefault;
  String? _orgAlias;
  String? _orgType;

  String? get orgPostId => _orgPostId;
  String? get orgId => _orgId;
  String? get orgName => _orgName;
  String? get postId => _postId;
  String? get postName => _postName;
  String? get districtLevel => _districtLevel;
  int? get isDefault => _isDefault;
  String? get orgAlias => _orgAlias;
  String? get orgType => _orgType;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['orgPostId'] = _orgPostId;
    map['orgId'] = _orgId;
    map['orgName'] = _orgName;
    map['postId'] = _postId;
    map['postName'] = _postName;
    map['districtLevel'] = _districtLevel;
    map['isDefault'] = _isDefault;
    map['orgAlias'] = _orgAlias;
    map['orgType'] = _orgType;
    return map;
  }
}

/// roleId : "7f8da0b5-fb76-48ca-ab0b-6d8caf106934"
/// roleName : "生产科长"
/// roleCode : "PRODUCTION_SECTION_CHIEF"
/// sourceId : "921b059b-bf62-4df0-9e7f-c5f54f3bda22"
/// sourceType : "U"
/// roleType : 2

UiasRoleList uiasRoleListFromJson(String str) =>
    UiasRoleList.fromJson(json.decode(str));
String uiasRoleListToJson(UiasRoleList data) => json.encode(data.toJson());

class UiasRoleList {
  UiasRoleList({
    String? roleId,
    String? roleName,
    String? roleCode,
    String? sourceId,
    String? sourceType,
    int? roleType,
  }) {
    _roleId = roleId;
    _roleName = roleName;
    _roleCode = roleCode;
    _sourceId = sourceId;
    _sourceType = sourceType;
    _roleType = roleType;
  }

  UiasRoleList.fromJson(dynamic json) {
    _roleId = json['roleId'];
    _roleName = json['roleName'];
    _roleCode = json['roleCode'];
    _sourceId = json['sourceId'];
    _sourceType = json['sourceType'];
    _roleType = json['roleType'];
  }
  String? _roleId;
  String? _roleName;
  String? _roleCode;
  String? _sourceId;
  String? _sourceType;
  int? _roleType;

  String? get roleId => _roleId;
  String? get roleName => _roleName;
  String? get roleCode => _roleCode;
  String? get sourceId => _sourceId;
  String? get sourceType => _sourceType;
  int? get roleType => _roleType;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['roleId'] = _roleId;
    map['roleName'] = _roleName;
    map['roleCode'] = _roleCode;
    map['sourceId'] = _sourceId;
    map['sourceType'] = _sourceType;
    map['roleType'] = _roleType;
    return map;
  }
}
